package ar.edu.itba.it.cg.grupo01.impl.shape.shader;

import java.awt.Color;

import javax.vecmath.Point2f;
import javax.vecmath.Point3f;

import ar.edu.itba.it.cg.grupo01.api.shape.Shape;

public class StoneShader extends PerlinShader {

	public StoneShader(Color noNoise, Color fullNoise) {
		super(noNoise, fullNoise);
	}

	@Override
	public float getNoise(Shape shape, Point3f intersectionPoint) {
		Point2f uv = shape.getUVCoordinates(intersectionPoint);
		
		uv.scale(600);
		return  PerlinNoise.noise2(uv.x, uv.y);
	}

	@Override
	protected float getTurbulenceFunction(Point3f p, float noise,
			float frequency, int times) {
		/*
		 * float result = (1.0f / frequency) * Math.abs(noise); result *= 20;
		 * result -= Math.floor(result);
		 * 
		 * return result;
		 */

		float result = Math.abs(noise) / frequency;
		float fade = 2 * (times - frequency) / times;
		result += fade * Math.abs(noise) / frequency;
		return result;
	}

}
